import axios from "axios"
const state = {
    shopListByTypeId: [], // 存放的是根据店铺类别查找到的店铺
    shopTypeList: [], // 用于保存店铺类别列表
    allShopTypeList: [], // 所有店铺类别,
    shopList: [] // 所有店铺
}
const mutations = {
    changeShopListByTypeId(state, shopList) {
        state.shopListByTypeId = shopList
    },
    changeShopTypeList(state, shopTypeList) {
        state.shopTypeList = shopTypeList
    },
    changeAllShopTypeList(state, shopTypeList) {
        state.allShopTypeList = shopTypeList
    },
    changeShopList(state, shopList) {
        state.shopList = shopList
    }
}
const actions = {
    getShopListByShopTypeId({ commit }, shopTypeId) {
        axios.get('/shopList/' + shopTypeId)
            .then(data => {
                commit('changeShopListByTypeId', data.shopList)
            })
    },
    getShopTypeList({ commit }, params) {
        axios.get('/shopTypeList', {
            params
        }).then(data => {
            commit('changeShopTypeList', data.shopTypeList)
        })
    },
    allShopTypeList({ commit }) {
        axios.get('/allShopTypeList')
            .then(data => {
                commit('changeAllShopTypeList', data.shopTypeList)
            })
    },
    getShopList({ commit }, params) {
        axios.get('/shopList', {
            params
        }).then(data => {
            commit('changeShopList', data.shopList)
        })
    },
    deleteShopList({ dispatch }, id) {
        axios.delete('/shopTypeList/' + id, {
            params: {
                id
            }
        }).then(data => {
            if (data.ok === 1) {
                dispatch('getShopTypeList')

            }
        })
    },
    deleteAllShopList({ dispatch }, id) {
        axios.delete('/shopList/' + id, {
            params: {
                id
            }
        })
            .then(data => {
                if (data.ok === 1) {
                    dispatch('getShopList')
                }
            })
    }
}

export default {
    state,
    mutations,
    actions
}

